﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using HotelManager.DataAccess;
using HotelManager.Model;

namespace HotelManager.View
{
    public partial class FormKhachHang : Form
    {
        KhachHangAccess khachhangAccess = new KhachHangAccess();
        DataTable dsKhachhang = new DataTable();
        public FormKhachHang()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
            {
                this.Close();
            }
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            KhachHang kh = new KhachHang(txtMakhachhang.Text, txtHovaten.Text, DateTime.Parse(dtNgaySinh.Text), txtDiachi.Text, txtCMND.Text, txtQuocTich.Text, txtSdt.Text);
            if (khachhangAccess.themKhachHang(kh) == 0) { MessageBox.Show("Mã khách hàng tồn tại"); }
            else
            {
                MessageBox.Show("Thêm thành công");
            }
            FormKhachHang_Load(sender, e);
        }

        private void groupBox3_Enter(object sender, EventArgs e)
        {

        }

        private void cbbTimkiem_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void txtTimkiem_TextChanged(object sender, EventArgs e)
        {
            DataView dataView = new DataView();
            if (cbbTimkiem.SelectedItem == cbbTimkiem.Items[0])
            {
                dataView = khachhangAccess.timkiemMakh(txtMakhachhang.Text);
                dataGridView1.DataSource = dataView;
            }
            else
            {
                dataView = khachhangAccess.timkiemTenkh(txtTimkiem.Text);
                dataGridView1.DataSource = dataView;
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            KhachHang kh = new KhachHang(txtMakhachhang.Text, txtHovaten.Text, DateTime.Parse(dtNgaySinh.Text), txtDiachi.Text, txtCMND.Text, txtQuocTich.Text,txtSdt.Text);
            if (khachhangAccess.suaKhachHang(kh) == 0) { MessageBox.Show("Mã khách hàng không tồn tại"); }
            else
            {
                MessageBox.Show("Sửa thành công !");
            }
            FormKhachHang_Load(sender, e);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            KhachHang kh = new KhachHang(txtMakhachhang.Text, txtHovaten.Text, txtDiachi.Text, DateTime.Parse(dtNgaySinh.Text), txtCMND.Text, txtQuocTich.Text,txtSdt.Text);
            if (khachhangAccess.xoakh(kh)==0)
            {
                MessageBox.Show("Mã khách hàng không tồn tại");
            }
            else
            {
                MessageBox.Show("Xóa thành công");
            }
            FormKhachHang_Load(sender, e);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            txtMakhachhang.Text = dataGridView1.CurrentCell[0].Value.ToString();
            txtQuocTich.Text = dataGridView1.CurrentCell[1].Value.ToString();
            txtHovaten.Text = dataGridView1.CurrentCell[2].Value.ToString();
            txtCMND.Text = dataGridView1.CurrentCell[3].Value.ToString();
            txtDiachi = dataGridView1.CurrentCell[4].Value.ToString();
            txtSdt = dataGridView1.CurrentCell[5].Value.ToString();
        }

        private void txtSdt_TextChanged(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void cbbGioitinh_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void txtDiachi_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtHovaten_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtMakhachhang_TextChanged(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void dtNgaySinh_ValueChanged(object sender, EventArgs e)
        {

        }

        private void txtQuocTich_TextChanged(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void txtCMND_TextChanged(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
    }
}
